package com.xxl.job.executor.core.config;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
import org.slf4j.MDC;
import org.springframework.util.StringUtils;

import static com.xxl.job.executor.core.config.XxlJobAspect.XXL_JOB_LOG_PATH;

/**
 * @Author:
 * @Description: xxljob日志自定义过滤器
 * @DateTime: 2021/12/26 23:10
 **/
public class XxlJobLogFilter extends Filter<ILoggingEvent> {

    @Override
    public FilterReply decide(ILoggingEvent event) {
        String xxlJobLogFile = MDC.get(XXL_JOB_LOG_PATH);
        if (!StringUtils.isEmpty(xxlJobLogFile)) {
            return FilterReply.ACCEPT;
        }
        return FilterReply.DENY;
    }
}

